package stdying.showstyle;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

/**
 * activity的切换效果，重点是动画实现
 *参考 http://www.iteye.com/topic/1078318
 */
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
    //底部弹出淡入
    private Button showBut;

    //activity以dialog像是弹出
    private Button activityBut;

    //左右滑动
    private Button leftRigth;

    //下拉选项
    private Spinner spinner;
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();

        String[] ls = getResources().getStringArray(R.array.anim_type);
        ArrayAdapter<String> animType  = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,ls);
        animType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(animType);
        spinner.setSelection(0);

    }


    private void initView(){
        showBut = (Button) findViewById(R.id.button);
        activityBut = (Button) findViewById(R.id.button2);
        leftRigth  = (Button) findViewById(R.id.button3);
        spinner = (Spinner) findViewById(R.id.spinner);
        button = (Button) findViewById(R.id.button4);

        showBut.setOnClickListener(this);
        activityBut.setOnClickListener(this);
        leftRigth.setOnClickListener(this);
        button.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button:
                AlertDialog dialog = new AlertDialog.Builder(this)
                        .setTitle("Title")
                        .setMessage("弹出效果")
                        .create();
                Window window = dialog.getWindow();
                window.setGravity(Gravity.BOTTOM);
                window.setWindowAnimations(R.style.myInOut);
                dialog.show();
                break;

            //dialog形式从底部弹出
            case R.id.button2:
                Intent intent = new Intent(this,ShowActivity.class);
                startActivity(intent);
                break;

            //左右滑动
            case R.id.button3:
                Intent intentDemo = new Intent(this,DemoActivity.class);
                startActivity(intentDemo);
                overridePendingTransition(R.anim.in_from_right,R.anim.out_to_left);
                break;

            //多个集合效果展示
            case R.id.button4:

                Intent it = new Intent(this, DemoActivity.class);
                startActivity(it);

                switch (spinner.getSelectedItemPosition()) {
                    case 0:
                        overridePendingTransition(R.anim.fade, R.anim.hold);
                        break;
                    case 1:
                        overridePendingTransition(R.anim.my_scale_action,
                                R.anim.my_alpha_action);
                        break;
                    case 2:
                        overridePendingTransition(R.anim.scale_rotate,
                                R.anim.my_alpha_action);
                        break;
                    case 3:
                        overridePendingTransition(R.anim.scale_translate_rotate,
                                R.anim.my_alpha_action);
                        break;
                    case 4:
                        overridePendingTransition(R.anim.scale_translate,
                                R.anim.my_alpha_action);
                        break;
                    case 5:
                        overridePendingTransition(R.anim.hyperspace_in,
                                R.anim.hyperspace_out);
                        break;
                    case 6:
                        overridePendingTransition(R.anim.push_left_in,
                                R.anim.push_left_out);
                        break;
                    case 7:
                        overridePendingTransition(R.anim.push_up_in,
                                R.anim.push_up_out);
                        break;
                    case 8:
                        overridePendingTransition(R.anim.slide_left,
                                R.anim.slide_right);
                        break;
                    case 9:
                        overridePendingTransition(R.anim.wave_scale,
                                R.anim.my_alpha_action);
                        break;
                    case 10:
                        overridePendingTransition(R.anim.zoom_enter,
                                R.anim.zoom_exit);
                        break;
                    case 11:
                        overridePendingTransition(R.anim.slide_up_in,
                                R.anim.slide_down_out);
                        break;
                }

                break;
            default:
        }
    }
}
